package jsyf.oa.service.crm;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.dao.crm.EquipmentBrandDao;
import jsyf.oa.dao.crm.EquipmentModelDao;
import jsyf.oa.entity.crm.EquipmentBrandEntity;
import jsyf.oa.entity.crm.EquipmentModelEntity;
import jsyf.oa.facade.crm.EquipmentModelFacade;
import jsyf.oa.facade.crm.EquipmentTypeFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/12/19 0019.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class EquipmentModelService implements EquipmentModelFacade {

    @Autowired
    private EquipmentModelDao equipmentModelDao;


    @Override
    public String save(String jsonData) {
        EquipmentModelEntity entity = JSON.toJavaObject(JSON.parseObject(jsonData), EquipmentModelEntity.class);
        equipmentModelDao.add(entity);
        return entity.getId();
    }

    @Override
    public JSONObject getModelList() {
        List<JSONObject> records = equipmentModelDao.getJSONListByCondition("",null);
        //返回
        JSONObject objResult = new JSONObject();
        objResult.put("records", records);
        return objResult;
    }

    @Override
    public JSONObject getById(String id) {
        JSONObject equipmentModel = equipmentModelDao.getJSONById(id);
        return equipmentModel;
    }
}
